package com.poet.df.dao;

import java.io.Serializable;
import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;

@Repository
public class BaseDao extends HibernateDaoSupport {

	public <T> Serializable save(T t){
		Serializable id = null;
		try {
			id = super.getHibernateTemplate().save(t);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return id;
	}
	
	public <T> boolean update(T t){
		boolean updateFlag = false;
		try {
			super.getHibernateTemplate().update(t);
			updateFlag = true;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return updateFlag;
	}
	
	public <T> boolean delete(T t){
		boolean deleteFlag = false;
		try {
			super.getHibernateTemplate().delete(t);
			deleteFlag = true;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return deleteFlag;
	}
	
	public <T> T get(Serializable id,Class<T> clazz){
		return super.getHibernateTemplate().get(clazz, id);
	}
	
	public <T> List<T> find(final String hql,final Object... args){
		return super.getHibernateTemplate().find(hql,args);
	}
	
	public <T> List<T> findAll(Class<T> clazz){
		String hql = "FROM " + clazz.getName();
		return this.find(hql);
	}
	
}
